﻿using SUNRPA.CONTROLS.IMPL.domain;
using SUNRPA.CONTROLS.IMPL.domain.constant;
using SUNRPA.CONTROLS.IMPL.domain.flowItemParam;
using SUNRPA.CONTROLS.IMPL.domain.flowRunningVar;
using SUNRPA.CONTROLS.IMPL.util;
using System.Collections.Concurrent;

namespace SUNRPA.CONTROLS.IMPL.controls {
    /// <summary>
    /// TODO: 1、可以选择当前时间的前后天数
    ///       2、支持更多的时间格式，如月-日
    /// </summary>
    public class GetDateNAction:BaseControlActions {
        public override int Execute(int currentIndex, FlowItem item, ConcurrentDictionary<string, ConcurrentDictionary<string, RPAVariableDefineWrapper>> globleData, List<FlowItem> flowItems) {
            GetDateNParam? param = item.ControlParam as GetDateNParam;
            string outVarName = param.OutVarName;
            this.GetStringVar(ref outVarName, globleData);

            DateTime date = DateTime.Now;
            if(param.DateType != 0) { 
                date = param.PickDate;
            }
            this.saveVar(globleData, outVarName, new DateModel(outVarName, date), DefaultContents.RUNNING_PARAM);
            return currentIndex;
        }
    }
}
